`
https://leetcode.cn/problems/remove-duplicates-from-sorted-list-ii/
`

/**
 * Definition for singly-linked list.
 * function ListNode(val, next) {
 *     this.val = (val===undefined ? 0 : val)
 *     this.next = (next===undefined ? null : next)
 * }
 */
/**
 * @param {ListNode} head
 * @return {ListNode}
 */
var deleteDuplicates = function (head) {
  if (head === null || head.next === null) return head
  let curRepNum = Infinity

  const dummy = new ListNode(Infinity, head)

  let left = dummy, right = dummy.next

  // 遍历整个链表
  while (right !== null && right.next !== null) {

    // 右指针遇到跟下一个结点有相等的值时
    if (right.val === right.next.val) {
      // 将值保存起来
      curRepNum = right.val
      // 删掉所有等于这个值的结点
      while (left.next !== null && left.next.val === curRepNum) {
        // 删除 right 指向的结点
        left.next = left.next.next
        right = left.next
      }
      continue
    }

    // 左右指针一起前进
    left = left.next
    right = right.next
  }

  return dummy.next
};